home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / 1942.c next >
C/C++ Source or Header  |  2000-05-04  |  8KB  |  292 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *c1942_backgroundram;
  15. size_t c1942_backgroundram_size;
  16. unsigned char *c1942_scroll;
  17. unsigned char *c1942_palette_bank;
  18. static unsigned char *dirtybuffer2;
  19. static struct osd_bitmap *tmpbitmap2;
  20. static int flipscreen;
  21.  
  22.  
  23.  
  24. /***************************************************************************
  25.  
  26.   Convert the color PROMs into a more useable format.
  27.  
  28.   1942 has three 256x4 palette PROMs (one per gun) and three 256x4 lookup
  29.   table PROMs (one for characters, one for sprites, one for background tiles).
  30.   The palette PROMs are connected to the RGB output this way:
  31.  
  32.   bit 3 -- 220 ohm resistor  -- RED/GREEN/BLUE
  33.         -- 470 ohm resistor  -- RED/GREEN/BLUE
  34.         -- 1  kohm resistor  -- RED/GREEN/BLUE
  35.   bit 0 -- 2.2kohm resistor  -- RED/GREEN/BLUE
  36.  
  37. ***************************************************************************/
  38. void c1942_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  39. {
  40.     int i;
  41.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  42.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  43.  
  44.  
  45.     for (i = 0;i < Machine->drv->total_colors;i++)
  46.     {
  47.         int bit0,bit1,bit2,bit3;
  48.  
  49.  
  50.         /* red component */
  51.         bit0 = (color_prom[0] >> 0) & 0x01;
  52.         bit1 = (color_prom[0] >> 1) & 0x01;
  53.         bit2 = (color_prom[0] >> 2) & 0x01;
  54.         bit3 = (color_prom[0] >> 3) & 0x01;
  55.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  56.         /* green component */
  57.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  58.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  59.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  60.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  61.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  62.         /* blue component */
  63.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  64.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  65.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  66.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  67.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  68.  
  69.         color_prom++;
  70.     }
  71.  
  72.     color_prom += 2*Machine->drv->total_colors;
  73.     /* color_prom now points to the beginning of the lookup table */
  74.  
  75.  
  76.     /* characters use colors 128-143 */
  77.     for (i = 0;i < TOTAL_COLORS(0);i++)
  78.         COLOR(0,i) = *(color_prom++) + 128;
  79.  
  80.     /* background tiles use colors 0-63 in four banks */
  81.     for (i = 0;i < TOTAL_COLORS(1)/4;i++)
  82.     {
  83.         COLOR(1,i) = *color_prom;
  84.         COLOR(1,i+32*8) = *color_prom + 16;
  85.         COLOR(1,i+2*32*8) = *color_prom + 32;
  86.         COLOR(1,i+3*32*8) = *color_prom + 48;
  87.         color_prom++;
  88.     }
  89.  
  90.     /* sprites use colors 64-79 */
  91.     for (i = 0;i < TOTAL_COLORS(2);i++)
  92.         COLOR(2,i) = *(color_prom++) + 64;
  93. }
  94.  
  95.  
  96.  
  97. /***************************************************************************
  98.  
  99.   Start the video hardware emulation.
  100.  
  101. ***************************************************************************/
  102. int c1942_vh_start(void)
  103. {
  104.     if (generic_vh_start() != 0)
  105.         return 1;
  106.  
  107.     if ((dirtybuffer2 = malloc(c1942_backgroundram_size)) == 0)
  108.     {
  109.         generic_vh_stop();
  110.         return 1;
  111.     }
  112.     memset(dirtybuffer2,1,c1942_backgroundram_size);
  113.  
  114.     /* the background area is twice as wide as the screen (actually twice as tall, */
  115.     /* because this is a vertical game) */
  116.     if ((tmpbitmap2 = osd_create_bitmap(2*Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  117.     {
  118.         free(dirtybuffer2);
  119.         generic_vh_stop();
  120.         return 1;
  121.     }
  122.  
  123.     return 0;
  124. }
  125.  
  126.  
  127.  
  128. /***************************************************************************
  129.  
  130.   Stop the video hardware emulation.
  131.  
  132. ***************************************************************************/
  133. void c1942_vh_stop(void)
  134. {
  135.     osd_free_bitmap(tmpbitmap2);
  136.     free(dirtybuffer2);
  137.     generic_vh_stop();
  138. }
  139.  
  140.  
  141.  
  142. WRITE_HANDLER( c1942_background_w )
  143. {
  144.     if (c1942_backgroundram[offset] != data)
  145.     {
  146.         dirtybuffer2[offset] = 1;
  147.  
  148.         c1942_backgroundram[offset] = data;
  149.     }
  150. }
  151.  
  152.  
  153.  
  154. WRITE_HANDLER( c1942_palette_bank_w )
  155. {
  156.     if (*c1942_palette_bank != data)
  157.     {
  158.         memset(dirtybuffer2,1,c1942_backgroundram_size);
  159.         *c1942_palette_bank = data;
  160.     }
  161. }
  162.  
  163.  
  164.  
  165. WRITE_HANDLER( c1942_flipscreen_w )
  166. {
  167.     if (flipscreen != (data & 0x80))
  168.     {
  169.         flipscreen = data & 0x80;
  170.         memset(dirtybuffer2,1,c1942_backgroundram_size);
  171.     }
  172. }
  173.  
  174.  
  175.  
  176. /***************************************************************************
  177.  
  178.   Draw the game screen in the given osd_bitmap.
  179.   Do NOT call osd_update_display() from this function, it will be called by
  180.   the main emulation engine.
  181.  
  182. ***************************************************************************/
  183. void c1942_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  184. {
  185.     int offs;
  186.  
  187.  
  188.     for (offs = c1942_backgroundram_size - 1;offs >= 0;offs--)
  189.     {
  190.         if ((offs & 0x10) == 0 && (dirtybuffer2[offs] != 0 || dirtybuffer2[offs + 16] != 0))
  191.         {
  192.             int sx,sy,flipx,flipy;
  193.  
  194.  
  195.             dirtybuffer2[offs] = dirtybuffer2[offs + 16] = 0;
  196.  
  197.             sx = offs / 32;
  198.             sy = offs % 32;
  199.             flipx = c1942_backgroundram[offs + 16] & 0x20;
  200.             flipy = c1942_backgroundram[offs + 16] & 0x40;
  201.             if (flipscreen)
  202.             {
  203.                 sx = 31 - sx;
  204.                 sy = 15 - sy;
  205.                 flipx = !flipx;
  206.                 flipy = !flipy;
  207.             }
  208.  
  209.             drawgfx(tmpbitmap2,Machine->gfx[1],
  210.                     c1942_backgroundram[offs] + 2*(c1942_backgroundram[offs + 16] & 0x80),
  211.                     (c1942_backgroundram[offs + 16] & 0x1f) + 32 * *c1942_palette_bank,
  212.                     flipx,flipy,
  213.                     16 * sx,16 * sy,
  214.                     0,TRANSPARENCY_NONE,0);
  215.         }
  216.     }
  217.  
  218.  
  219.     /* copy the background graphics */
  220.     {
  221.         int scroll;
  222.  
  223.  
  224.         scroll = -(c1942_scroll[0] + 256 * c1942_scroll[1]);
  225.         if (flipscreen) scroll = 256-scroll;
  226.  
  227.         copyscrollbitmap(bitmap,tmpbitmap2,1,&scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  228.     }
  229.  
  230.  
  231.     /* Draw the sprites. */
  232.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  233.     {
  234.         int i,code,col,sx,sy,dir;
  235.  
  236.  
  237.         code = (spriteram[offs] & 0x7f) + 4*(spriteram[offs + 1] & 0x20)
  238.                 + 2*(spriteram[offs] & 0x80);
  239.         col = spriteram[offs + 1] & 0x0f;
  240.         sx = spriteram[offs + 3] - 0x10 * (spriteram[offs + 1] & 0x10);
  241.         sy = spriteram[offs + 2];
  242.         dir = 1;
  243.         if (flipscreen)
  244.         {
  245.             sx = 240 - sx;
  246.             sy = 240 - sy;
  247.             dir = -1;
  248.         }
  249.  
  250.         /* handle double / quadruple height (actually width because this is a rotated game) */
  251.         i = (spriteram[offs + 1] & 0xc0) >> 6;
  252.         if (i == 2) i = 3;
  253.  
  254.         do
  255.         {
  256.             drawgfx(bitmap,Machine->gfx[2],
  257.                     code + i,col,
  258.                     flipscreen,flipscreen,
  259.                     sx,sy + 16 * i * dir,
  260.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,15);
  261.  
  262.             i--;
  263.         } while (i >= 0);
  264.     }
  265.  
  266.  
  267.     /* draw the frontmost playfield. They are characters, but draw them as sprites */
  268.     for (offs = videoram_size - 1;offs >= 0;offs--)
  269.     {
  270.         if (videoram[offs] != 0x30)    /* don't draw spaces */
  271.         {
  272.             int sx,sy;
  273.  
  274.  
  275.             sx = offs % 32;
  276.             sy = offs / 32;
  277.             if (flipscreen)
  278.             {
  279.                 sx = 31 - sx;
  280.                 sy = 31 - sy;
  281.             }
  282.  
  283.             drawgfx(bitmap,Machine->gfx[0],
  284.                     videoram[offs] + 2 * (colorram[offs] & 0x80),
  285.                     colorram[offs] & 0x3f,
  286.                     flipscreen,flipscreen,
  287.                     8*sx,8*sy,
  288.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  289.         }
  290.     }
  291. }
  292.